package com.singzi.leetcode.N100;

import java.util.Arrays;

public class T0080 {
    public static void main(String[] args) {
        int[] nums = {0,0,0,0,0,0,0};
        Solution0080 solution0080 = new Solution0080();
        System.out.println(Arrays.toString(nums));
        int n = solution0080.removeDuplicates(nums);
        System.out.println(Arrays.toString(nums));
        System.out.println(n);

    }
}
class Solution0080 {
    public int removeDuplicates(int[] nums) {
        int temp = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {

            if(nums[i]!=temp){
                count = 1;
                temp = nums[i];
                continue;
            }
            else {
                count++;
                if(count<=2){
                    continue;
                }
            }
            nums[i] = -10001;
        }
        System.out.println(Arrays.toString(nums));
        int result = 1;
        for (int num : nums) {
            if (num != -10001) result++;
        }
        temp = 1;
        for (int i = 1; i < result; i++) {
            for (int j = temp; j < nums.length; j++) {
                if(nums[j] != -10001){
                    nums[i] = nums[j];
                    temp = j+1;
                    break;
                }
            }

        }
        return result-1;

    }
}